package thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * 如果一个类已经继承了其他的类，这时候选择实现Runnable接口
 * 启动方式不同
 * 如果想用返回值 需要实现Callable 接口 ，必须配合FutureTask使用
 *
 */
public class NewThread {
    public static void main(String[] args) throws ExecutionException, InterruptedException {

        Thread1 thread1 = new Thread1("zhangsan");
        thread1.start();

        Thread thread = new Thread(new Thread2(),"李四");
        thread.start();


        FutureTask<String> futureTask = new FutureTask<>(new Thread3());
        Thread thread2 = new Thread(futureTask,"Callable-0");
        thread2.start();
        String s = futureTask.get();
        System.out.println(s);

    }
}

class  Thread1 extends Thread{
    public Thread1(String name) {
        super(name);
    }

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName()+"欢迎进入多线程");
    }
}
class Thread2 implements Runnable{

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName()+"环境进入Runnable 多线程");
    }
}
class Thread3 implements Callable<String>{


    @Override
    public String call() throws Exception {
        return Thread.currentThread().getName()+"欢迎进入Callable 多线程环境";
    }
}
